package admin.controllers;

import helpers.PaginatorHelper;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import admin.data.OwnerDomainData;

import models.OwnerDomainModel;


public class ListVerifyDomainChangeServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		int page = 1;
		try {
			page = Integer.parseInt((String) request.getParameter("page"));
		} catch (Exception e) {}
		
		OwnerDomainData ownerData = new OwnerDomainData();
		ownerData.setLimit(20);
		ownerData.setPage(page);
		ArrayList<OwnerDomainModel> domains = ownerData.getVerifyDomainChange();
		
		boolean nextPage = false;
		boolean prevPage = false;
		
		if (domains.size() == ownerData.getLimit()) {
			nextPage = true;
		}
		
		if (page > 1) {
			prevPage = true;
		}
		
		//Get paginate
		String queryString = request.getQueryString();
		String requestURI = request.getRequestURI();
		PaginatorHelper paginator = new PaginatorHelper(queryString);
		paginator.setUrl(requestURI);
		
		request.setAttribute("paginator", paginator);
		request.setAttribute("prevPage", prevPage);
		request.setAttribute("nextPage", nextPage);
		request.setAttribute("domains", domains);
		request.setAttribute("page", page);
		try {
			request.getRequestDispatcher("/admin/pages/list_verify_domain_change.jsp").forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
